package main

import "fmt"

// func showAddr(x []int) []int {

// 	fmt.Printf("x %p %p l=%-2d c=%-2d %v\n", &x, &x[0], len(x), cap(x), x)
// 	if len(x) > 0 {
// 		x[0] = 100

// 	}
// 	x = append(x, 111)
// 	fmt.Printf("x %p %p l=%-2d c=%-2d %v\n", &x, &x[0], len(x), cap(x), x)
// 	return x
// }

func showAddr(x []int) []int {

	fmt.Printf("In showAddr: %T %p %p l=%-2d, c=%-2d %v\n", x, &x, &x[0], len(x), cap(x), x)
	if len(x) > 0 {
		x[0] = 100
	}
	x = append(x, 111)
	fmt.Printf("In showAddr: %T %p %p l=%-2d, c=%-2d %v\n", x, &x, &x[0], len(x), cap(x), x)
	return x
}
func main() {

	s0 := []int{10, 30, 50, 70, 90, 110, 120, 130}
	fmt.Printf("s0 %p %p, l=%-2d , c=%-2d, %v\n", &s0, &s0[0], len(s0), cap(s0), s0)
	//s1 := []int{10, 30, 50, 70, 90}
	//s1 := make([]int, 5, 8)
	s1 := s0[:5]
	fmt.Printf("s1 %p %p, l=%-2d , c=%-2d, %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	s2 := s1
	fmt.Printf("s2 %p %p, l=%-2d , c=%-2d, %v\n", &s2, &s2[0], len(s2), cap(s2), s2)
	s3 := s1[:]
	fmt.Printf("s3 %p %p, l=%-2d , c=%-2d, %v\n", &s3, &s3[0], len(s3), cap(s3), s3)
	s4 := s1[1:]
	fmt.Printf("s4 %p %p, l=%-2d , c=%-2d, %v\n", &s4, &s4[0], len(s4), cap(s4), s4)

	s5 := s1[1:4]
	fmt.Printf("s5 %p %p, l=%-2d , c=%-2d, %v\n", &s5, &s5[0], len(s5), cap(s5), s5)
	// s5 = append(s5, 111)
	// fmt.Printf("s5 %p %p, l=%-2d , c=%-2d, %v\n", &s5, &s5[0], len(s5), cap(s5), s5)
	// fmt.Printf("s1 %p %p, l=%-2d , c=%-2d, %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	//s6 := s1[5:] // len  cap
	//s6 := s1[6:]
	//s6 := s1[:4]
	//s6 := s1[6:7]
	//s6 := s1[6:8]
	//s6 := s1[6:6]
	//s6 := s1[4:]
	//s6 := s1[4:8]
	s6 := s1[:0]
	//fmt.Printf("s6 %p %p, l=%-2d , c=%-2d, %v\n", &s6, &s6[0], len(s6), cap(s6), s6)
	fmt.Printf("s6 %p, l=%-2d , c=%-2d, %v\n", &s6, len(s6), cap(s6), s6)
	print(s6)
	// s7 := s1[1:1]
	// fmt.Printf("s7 %p, l=%-2d , c=%-2d, %v\n", &s7, len(s7), cap(s7), s7)
	// //print(s7)
	// //fmt.Printf("s7 %p %p, l=%-2d , c=%-2d, %v\n", &s7, &s7[0], len(s7), cap(s7), s7)
	// // s8 := s1[4:4]
	// //s7 = append(s7, -1)
	// //fmt.Printf("s7 %p %p, l=%-2d , c=%-2d, %v\n", &s7, &s7[0], len(s7), cap(s7), s7)
	// s8 := s1[4:4]
	// fmt.Printf("s8 %p, l=%-2d , c=%-2d, %v\n", &s8, len(s8), cap(s8), s8)
	// //print(s8)
	// s8 = append(s8, -2)
	// fmt.Printf("s8 %p %p , l=%-2d , c=%-2d, %v\n", &s8, &s8[0], len(s8), cap(s8), s8)
	// s9 := s1[5:5]
	// fmt.Printf("s9 %p, l=%-2d , c=%-2d, %v\n", &s9, len(s9), cap(s9), s9)
	// print(s9)
	// s9 = append(s9, 100)
	// fmt.Printf("s9 %p %p, l=%-2d , c=%-2d, %v\n", &s9, &s9[0], len(s9), cap(s9), s9)
	// slice
	// s1 := []int{10, 30, 50}
	// fmt.Printf("s1 %T %p %p l=%-2d c=%-2d %v\n", s1, &s1, &s1[0], len(s1), cap(s1), s1)
	// s2 := s1

	// fmt.Printf("s2 %T %p %p l=%-2d c=%-2d %v\n", s2, &s2, &s2[0], len(s2), cap(s2), s2)
	// fmt.Println("~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
	// s3 := showAddr(s1)
	// fmt.Printf("s1 %T %p %p l=%-2d c=%-2d %v\n", s1, &s1, &s1[0], len(s1), cap(s1), s1)
	// fmt.Printf("s2 %T %p %p l=%-2d c=%-2d %v\n", s2, &s2, &s2[0], len(s2), cap(s2), s2)
	// fmt.Printf("s3 %T %p %p l=%-2d c=%-2d %v\n", s3, &s3, &s3[0], len(s3), cap(s3), s3)

	// // array
	// s1 := [3]int{10, 30, 50}
	// s2 := s1
	// fmt.Printf("s1 %p %p l=%-2d c=%-2d %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	// fmt.Printf("s2 %p %p l=%-2d c=%-2d %v\n", &s2, &s2[0], len(s2), cap(s2), s2)

	// var a []int
	// fmt.Printf("%p, l=%-2d, c=%-2d, %v\n", &a, len(a), cap(a), a)
	// a = append(a, 10)
	// fmt.Printf("%p, %p, l=%-2d, c=%-2d, %v\n", &a, &a[0], len(a), cap(a), a)
	// s1 := []int{10}
	// fmt.Printf("s1 %p %p l=%-2d c=%-2d %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	// s1 = make([]int, 2, 5)
	// fmt.Printf("s1 %p %p l=%-2d c=%-2d %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	// s1 = append(s1, 100)
	// fmt.Printf("s1 %p %p l=%-2d c=%-2d %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	// s2 := append(s1, 1, 2)
	// fmt.Printf("s1: %p %p l=%-2d c=%-2d %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	// fmt.Printf("s2: %p %p l=%-2d c=%-2d %v\n", &s2, &s2[0], len(s2), cap(s2), s2)

	// s3 := append(s1, -1)
	// fmt.Printf("s1: %p %p l=%-2d c=%-2d %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	// fmt.Printf("s2: %p %p l=%-2d c=%-2d %v\n", &s2, &s2[0], len(s2), cap(s2), s2)
	// fmt.Printf("s3: %p %p l=%-2d c=%-2d %v\n", &s3, &s3[0], len(s3), cap(s3), s3)
	// s4 := append(s3, 3, 4, 5) //底层数组长度不能变，另外再开一个数组
	// fmt.Printf("s1: %p %p l=%-2d c=%-2d %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	// fmt.Printf("s2: %p %p l=%-2d c=%-2d %v\n", &s2, &s2[0], len(s2), cap(s2), s2)
	// fmt.Printf("s3: %p %p l=%-2d c=%-2d %v\n", &s3, &s3[0], len(s3), cap(s3), s3)
	// fmt.Printf("s4: %p %p l=%-2d c=%-2d %v\n", &s4, &s4[0], len(s4), cap(s4), s4)
	// s5 := append(s4, 6, 7, 8, 9)
	// fmt.Printf("s1: %p %p l=%-2d c=%-2d %v\n", &s1, &s1[0], len(s1), cap(s1), s1)
	// fmt.Printf("s2: %p %p l=%-2d c=%-2d %v\n", &s2, &s2[0], len(s2), cap(s2), s2)
	// fmt.Printf("s3: %p %p l=%-2d c=%-2d %v\n", &s3, &s3[0], len(s3), cap(s3), s3)
	// fmt.Printf("s4: %p %p l=%-2d c=%-2d %v\n", &s4, &s4[0], len(s4), cap(s4), s4)
	// fmt.Printf("s5: %p %p l=%-2d c=%-2d %v\n", &s5, &s5[0], len(s5), cap(s5), s5)

}
